package jcu.ict.profaid;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class SignDbAdapter {
		public static final String KEY_USER_ID = "user_id";
		public static final String KEY_USERNAME = "username";
		public static final String KEY_EMAIL = "email";
		public static final String KEY_PHONE_NUMBER = "phone";

		private static final String DATABASE_TABLE = "sign";

		private Context context;

		private DatabaseHelper DBHelper;
		private SQLiteDatabase db;

		public SignDbAdapter(Context ctx) {
			this.context = ctx;
		}

		// --- open the database ---
		public SignDbAdapter open() throws SQLException {
			DBHelper = new DatabaseHelper(context);
			db = DBHelper.getWritableDatabase();

			return this;
		}

		// ---closes the database ---
		public void close() {
			DBHelper.close();
		}

		// --- insert Question to question table ---
		public long insertSignUp(String name, String email,
				String phonenumber) {
			ContentValues initialValues = new ContentValues();
			initialValues.put(KEY_USERNAME, name);
			initialValues.put(KEY_EMAIL, email);
			initialValues.put(KEY_PHONE_NUMBER, phonenumber);
			return db.insert(DATABASE_TABLE, null, initialValues);
		}
		
		public Cursor populateSignIn (String Email) throws SQLException {
			Cursor mCursor =
					db.query(true, DATABASE_TABLE, new String[] {KEY_USERNAME,KEY_EMAIL,KEY_PHONE_NUMBER}, KEY_EMAIL + "=\"" + Email +  "\"", null,
							null, null, null, null);
			return mCursor;
		}
		
		public Cursor populateUserID (String Email) throws SQLException {
			Cursor mCursor =
					db.query(true, DATABASE_TABLE, new String[] {KEY_USER_ID}, KEY_EMAIL + "=\"" + Email +  "\"", null,
							null, null, null, null);
			return mCursor;
		}
		
	}

